package com.aj.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.aj.utils.Contants;

public class EnterPhoneActivity extends BaseActivity {

	private Button next;

	private EditText phone_edit;

	public static EnterPhoneActivity instance;

	private String pageFlag = "";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_enter_phone);
		initView();
	}

	private void initView() {
		instance = this;
		pageFlag = getIntent().getStringExtra(Contants.PAGEFLAG_STRING);
		if (pageFlag != null
				&& pageFlag.equals(Contants.FORGET_PAGEFLAG_STRING)) {
			setActionBarTitle(R.string.forget_title_text);
		} else {
			setActionBarTitle(R.string.register_title_text);
		}
		phone_edit = (EditText) findViewById(R.id.phone_edit);
		next = (Button) findViewById(R.id.next);
		ClickEvent clickEvent = new ClickEvent();
		next.setOnClickListener(clickEvent);
	}

	class ClickEvent implements OnClickListener {
		@Override
		public void onClick(View v) {
			Intent intent = null;
			switch (v.getId()) {
			case R.id.next:
				if (phone_edit.getText().toString().trim().length() == 0) {
					Toast.makeText(EnterPhoneActivity.this,
							getString(R.string.enter_phone_hinttext),
							Toast.LENGTH_LONG).show();
					return;
				}
				if (phone_edit.getText().toString().trim().length() < 11) {
					Toast.makeText(EnterPhoneActivity.this,
							getString(R.string.enter_phone_error_info),
							Toast.LENGTH_LONG).show();
					return;
				}
				intent = new Intent(
						Contants.ENTER_VERIFICATIONCODE_ACTIVITY_ACTION);
				intent.putExtra(Contants.PAGEFLAG_STRING, pageFlag);
				intent.putExtra(Contants.PHONEFLAG_STRING, phone_edit.getText()
						.toString().trim());
				startActivity(intent);
				break;
			default:
				break;
			}
		}
	}
}
